package edu.taru.view;

import javax.swing.JFrame;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import edu.taru.pojo.User;
import edu.taru.service.*;

import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.lang.reflect.Method;
import java.awt.event.ActionEvent;
import java.awt.Choice;
import java.awt.Color;

/**
 * 注册界面
 * @author chen
 *
 */
public class UpdateView extends JFrame{
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	String citys[] = {"北京","广州","上海","深圳","杭州","长沙","乌鲁木齐","兰州","西宁","郑州","武汉","成都","贵阳","天津"};
	String years[] = {"1987","1988","1989","1990","1991","1992","1993","1994","1995","1996","1997","1998","1999"};
	String months[] = {"1","2","3","4","5","6","7","8","9","10","11","12"};
	String dates[] = {"1","2","3","4","5","6","7","8","9","10",
			"11","12","13","14","15","16","17","18","19","20",
			"21","22","23","24","25","26","27","28","29","30","31"};
	private JTextField textField_3;
	//String id = FindView.id;
	
	public UpdateView(User user) {
		
		getContentPane().setForeground(new Color(102, 204, 153));
		setSize(551,330);
		setVisible(true);
		setTitle("修改信息");
		setLocationRelativeTo(null);
		getContentPane().setLayout(null);
		Services services = new Services();
		
		JLabel label = new JLabel("用户名");
		label.setBounds(138, 61, 54, 15);
		getContentPane().add(label);
		
		textField = new JTextField();
		textField.setBounds(197, 58, 143, 21);
		textField.setText(user.getUsername());
		getContentPane().add(textField);
		textField.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("姓名");
		lblNewLabel.setBounds(138, 92, 54, 15);
		getContentPane().add(lblNewLabel);
		
		textField_1 = new JTextField();
		textField_1.setBounds(197, 89, 143, 21);
		getContentPane().add(textField_1);
		//回显姓名
		/*Method method = FindView.class.getMethod("getSelectedRow",String.class);
		method.invoke();*/
		textField_1.setText(user.getName());
		textField_1.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setBounds(197, 117, 143, 21);
		//回显邮箱
		textField_2.setText(user.getEmail());
		getContentPane().add(textField_2);
		textField_2.setColumns(10);
		
		JLabel label_3 = new JLabel("邮箱");
		label_3.setBounds(138, 117, 54, 15);
		getContentPane().add(label_3);
		
		ButtonGroup  bg =new ButtonGroup();
		
		JButton button = new JButton("提交");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//获取参数
				String username = textField.getText();//用户名
				String name=textField_1.getText();//姓名
				
				String user_email= textField_2.getText();//邮箱
				
				//int index = comboBox.getSelectedIndex();//城市
				//String city=citys[index];
				
				String telphone = textField_3.getText();//电话
				User user = new User();
				user.setUsername(username);
				//user.setCity(city);
				user.setEmail(user_email);
				
				user.setName(name);
				user.setTelphone(telphone);
				
				if(user!=null) {
					Services services = new Services();
					services.update(user);
					
					JOptionPane.showMessageDialog(UpdateView.this, "修改成功");
				}else {
					JOptionPane.showMessageDialog(UpdateView.this, "修改失败");
				}
				UpdateView.this.dispose();
				
				
				
				
			}
		});
		button.setBounds(203, 221, 93, 23);
		getContentPane().add(button);
		
		JLabel label_9 = new JLabel("修改用户信息");
		label_9.setBounds(224, 26, 93, 15);
		getContentPane().add(label_9);
		
		JLabel label_10 = new JLabel("电话号码");
		label_10.setBounds(138, 182, 54, 15);
		getContentPane().add(label_10);
		
		textField_3 = new JTextField();
		textField_3.setBounds(197, 179, 143, 21);
		//回显电话
		textField_3.setText(user.getTelphone());
		getContentPane().add(textField_3);
		textField_3.setColumns(10);
		
		
	}
}
